#import "SceneDelegate.h"
#import "ViewController.h"
#import "AdvertiseView.h"
#import "AdVertiseViewController.h"
#import "GGZFBTabBarViewController.h"
#import "GDAdvertiseViewController.h"
#import "LaunchAnimationTool.h"
#import "GDAdVertiseView.h"
#import "GATabBarViewController.h"
@interface SceneDelegate ()

@end

@implementation SceneDelegate
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
    //适配iOS 13
    if(scene){
        UIWindowScene *windowScene = (UIWindowScene *)scene;
        self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
        self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);

        //1.宫崎骏
//        self.window.rootViewController = [[AdVertiseViewController alloc]init];
//        [self.window makeKeyAndVisible];
        
        //2.各种广告页的引导
        /**
         模拟接口请求，根据请求展示引导页   随机展示引导页
         */
        NSInteger typeNum = arc4random() % 5;
        switch (typeNum) {
            case 0:{
                //------动画引导页------
                GDAdvertiseViewController *gdAvertiseVC = [[GDAdvertiseViewController alloc]initWithMainVC:[[GATabBarViewController alloc]init] viewcontrollType:ShowLaunchAnimationViewController];
                self.window.rootViewController = gdAvertiseVC;
                [self.window makeKeyAndVisible];
                break;
            }
            case 1:{
                //------广告页------
                self.window.rootViewController = [[GATabBarViewController alloc]init];
                GDAdVertiseView *ADView = [[GDAdVertiseView alloc]initWithFrame:GDScreenBounds];
                ADView.imageUrl = @"https://upload-images.jianshu.io/upload_images/16037729-0181b6d051e188ab.jpg";
                //        让当前UIWindow变成keyWindow，并显示出来
                [self.window makeKeyAndVisible];
                //        注意调用的顺序，在根控制器加载完毕展示之后在 显示添加的视图
                [ADView show];
                break;
            }
            case 2:{
                //------仿keep开机动画------
                GDAdvertiseViewController *gdAvertiseVC = [[GDAdvertiseViewController alloc]initWithMainVC:[[GATabBarViewController alloc]init] viewcontrollType:AVLaunchViewController];
                NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"keep" ofType:@"mp4"];
                gdAvertiseVC.mp4URLStr = moviePath;
                self.window.rootViewController = gdAvertiseVC;
                [self.window makeKeyAndVisible];
                break;
            }
            case 3:{
                //------gif动图------
                GDAdvertiseViewController *gdAvertiseVC = [[GDAdvertiseViewController alloc]initWithMainVC:[[GATabBarViewController alloc]init] viewcontrollType:GifBackgroundLaunchViewController];
                gdAvertiseVC.gifImageStr = @"动图1";
                //        gdAvertiseVC.gifImageUrlStr = @"http://image76.360doc.com/DownloadImg/2014/07/1510/43430258_28";
                self.window.rootViewController = gdAvertiseVC;
                [self.window makeKeyAndVisible];
                break;
            }
            case 4:{
                //没有广告页
                self.window.rootViewController = [[GATabBarViewController alloc]init];
                [self.window makeKeyAndVisible];
                break;
            }
            default:
                break;
        }
        
        //------动画引导页------
//        GDAdvertiseViewController *gdAvertiseVC = [[GDAdvertiseViewController alloc]initWithMainVC:[[GATabBarViewController alloc]init] viewcontrollType:ShowLaunchAnimationViewController];
//        self.window.rootViewController = gdAvertiseVC;
//        [self.window makeKeyAndVisible];
        
        //------广告页------
        /**
         1.实现思路一
         通过控制器的形式弹出广告页，只能modal出广告页控制器，不能push出广告页控制器
         注意：广告详情页面是从首页push进去的！！！
         除了广告页之外，其他的都是可以很好的
         存在跳过的就都是广告页！！！
         */
//        GDAdvertiseViewController *gdAvertiseVC = [[GDAdvertiseViewController alloc]initWithMainVC:[[ViewController alloc]init] viewcontrollType:ADLaunchViewController];
////        广告页默认图片的链接
//        gdAvertiseVC.imageURL = @"https://upload-images.jianshu.io/upload_images/16037729-0181b6d051e188ab.jpg";
//        gdAvertiseVC.URLStr = @"http://www.jianshu.com/users/e39da354ce50/latest_articles";
        
        /**
         实现思路二
         正确思路：将广告图片视图添加到window上，点击图片后发送通知 由首页pushk广告页控制器
         */
//        self.window.rootViewController = [[GATabBarViewController alloc]init];
//        GDAdVertiseView *ADView = [[GDAdVertiseView alloc]initWithFrame:GDScreenBounds];
//        ADView.imageUrl = @"https://upload-images.jianshu.io/upload_images/16037729-0181b6d051e188ab.jpg";
////        让当前UIWindow变成keyWindow，并显示出来
//        [self.window makeKeyAndVisible];
////        注意调用的顺序，在根控制器加载完毕展示之后在 显示添加的视图
//        [ADView show];
        
        //-------新手引导--------
//        GDAdvertiseViewController *gdAvertiseVC = [[GDAdvertiseViewController alloc]initWithMainVC:[[GATabBarViewController alloc]init] viewcontrollType:GreenhandLaunchViewController];
//        gdAvertiseVC.imageArray = @[@"新手指导1",@"新手指导2"];
//        self.window.rootViewController = gdAvertiseVC;
//        [self.window makeKeyAndVisible];
        
        //------keep开机动画------
        /**
         如果真的是个视频是可以播放声音的，其余的动态的广告页都是个GIF图
         可以视频转GIF图！！
         */
//        AVLaunchViewController
//        GDAdvertiseViewController *gdAvertiseVC = [[GDAdvertiseViewController alloc]initWithMainVC:[[GATabBarViewController alloc]init] viewcontrollType:AVLaunchViewController];
//        NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"keep" ofType:@"mp4"];
//        gdAvertiseVC.mp4URLStr = moviePath;
//        self.window.rootViewController = gdAvertiseVC;
//        [self.window makeKeyAndVisible];
        
        //------gif动图------
//        GDAdvertiseViewController *gdAvertiseVC = [[GDAdvertiseViewController alloc]initWithMainVC:[[GATabBarViewController alloc]init] viewcontrollType:GifBackgroundLaunchViewController];
//        gdAvertiseVC.gifImageStr = @"动图1";
////        gdAvertiseVC.gifImageUrlStr = @"http://image76.360doc.com/DownloadImg/2014/07/1510/43430258_28";
//        self.window.rootViewController = gdAvertiseVC;
//        [self.window makeKeyAndVisible];
        
        
        //3.支付宝
//        self.window.rootViewController = [[GGZFBTabBarViewController alloc]init];
        
       //4.自定义工具类 实现动画效果广告页，但是无法实现跳转
//        self.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:[[ViewController alloc]init]];
        
        //让当前UIWindow变成keyWindow，并显示出来
//        [self.window makeKeyAndVisible];
        
        //注意调用的顺序，在根控制器加载完毕展示之后在 显示添加的视图
//        [ADView show];
        //必须是makezkey之后才是tool的使用
//        [LaunchAnimationTool showLaunchAnimationToWindowView];
    }
}

/*
 此处是才走shortcutItem跳转
 */
- (void)windowScene:(UIWindowScene *)windowScene performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
    NSString *type = shortcutItem.type;
    
    if([type isEqualToString:@"message"]){
        NSLog(@"新消息");
    }else if([type isEqualToString:@"search"]){
        NSLog(@"搜索");
    }else if([type isEqualToString:@"collect"]){
        NSLog(@"收藏");
    }else if([type isEqualToString:@"share"]){
        NSLog(@"分享");
    }
}

- (void)sceneDidDisconnect:(UIScene *)scene {
    // Called as the scene is being released by the system.
    // This occurs shortly after the scene enters the background, or when its session is discarded.
    // Release any resources associated with this scene that can be re-created the next time the scene connects.
    // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
}


- (void)sceneDidBecomeActive:(UIScene *)scene {
    // Called when the scene has moved from an inactive state to an active state.
    // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}


- (void)sceneWillResignActive:(UIScene *)scene {
    // Called when the scene will move from an active state to an inactive state.
    // This may occur due to temporary interruptions (ex. an incoming phone call).
}


- (void)sceneWillEnterForeground:(UIScene *)scene {
    // Called as the scene transitions from the background to the foreground.
    // Use this method to undo the changes made on entering the background.
}


- (void)sceneDidEnterBackground:(UIScene *)scene {
    // Called as the scene transitions from the foreground to the background.
    // Use this method to save data, release shared resources, and store enough scene-specific state information
    // to restore the scene back to its current state.
}


@end
